package com.kdzy.lshy.socity_server.common;


import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import java.util.ArrayList;
import java.util.List;

public class IdCardCheck {


    public Object check(String path){


        String bas64String =FileUtils.encryptToBase64(path);

        CloseableHttpClient httpClient = HttpClients.createDefault();
        HttpPost post =new HttpPost("https://v.apistore.cn/api/c9");
        List<NameValuePair> kvList = new ArrayList<NameValuePair>();
        kvList.add(new BasicNameValuePair("key","AKd0a47a0feb36e8fc273c84b1629573"));
        kvList.add(new BasicNameValuePair("bas64String",bas64String));
        kvList.add(new BasicNameValuePair("side","1"));


        StringEntity entity = null;
        String string = null;
        try {
            entity = new UrlEncodedFormEntity(kvList,"utf-8");
            post.setEntity(entity);
            CloseableHttpResponse response =httpClient.execute(post);
            string = EntityUtils.toString(response.getEntity());
            System.out.println(string);
            response.close();
            httpClient.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return string;
    }

    public static void main(String[] args) {
        new IdCardCheck().check("C:\\upload\\idcardZ.jpg");
    }
}
